package com.cms.controller.manage;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.cms.constant.MainConstant;
import com.cms.entity.vo.AdminVo;
import com.cms.entity.vo.JsonVo;
import com.cms.entity.vo.UserVo;
import com.cms.service.AdminService;
import com.cms.service.UserService;

/**
*@author:gang
*@version:
**/
@Controller
public class ManageBaseAction {
	protected final Logger logger = Logger.getLogger(this.getClass());

	@Autowired
	protected AdminService adminService;

	@Autowired
	protected UserService userService;

	/**
	 * 参数校验
	 * 
	 * @param json
	 *            json数据Bean
	 * @throws ValidateException
	 */
	protected <T> void validate(JsonVo<T> json) throws Exception {
		if (json.getErrors().size() > 0) {
			json.setResult(false);
			throw new Exception("有错误发生");
		} else {
			json.setResult(true);
		}
	}

	/**
	 * 从session中获得管理员的信息
	 * 
	 * @param request
	 * @return
	 */
	protected UserVo getUser(HttpServletRequest request) {
		UserVo User = (UserVo) request.getSession().getAttribute(
				MainConstant.SESSION_ID);
		return User;
	}
}
